package com.wlsk.license.common.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * 配置文件帮助类
 */
@Slf4j
public class PropertiesUtils {

    private static Map<String, String> propMap;

    /**
     * 加载配置文件内容
     * @param in
     */
    public static void initProperties(InputStream in) {
        Properties props = new Properties();
        propMap = new HashMap<>();
        try {
            props.load(in);
            Enumeration en = props.propertyNames();
            while (en.hasMoreElements()) {
                String key = (String) en.nextElement();
                String property = props.getProperty(key);
                propMap.put(key, property);
            }
            log.info("加载配置文件成功!-{}", propMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取配置文件值
     * @param key
     * @return
     */
    public static String get(String key) {
        return propMap.get(key);
    }
}
